<?php if (!defined('THINK_PATH')) exit();?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><?php echo C('APP_NAME');?>管理后台</title>
    <link rel="stylesheet" href="/Public/layui/css/layui.css">
    <script type="text/javascript" src="/Public/layui/layui.js"></script>
    <script src="//cdn.bootcss.com/jquery/3.1.1/jquery.min.js"></script>
    
</head>
<body>
<div style="margin: 15px;">
    
    <fieldset class="layui-elem-field">
        <legend>订单管理 - <?php echo (isset($detail['id'])?'编辑':'新增');?>订单</legend>
        <div class="layui-field-box">
            <form class="layui-form" action="">
                <?php if(isset($detail['id'])): ?><input type="hidden" name="id" value="<?php echo ($detail['id']); ?>"><?php endif; ?>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 批次</label>
                    <div class="layui-input-block">
                        <select name="batch" lay-verify="required">
                            <option value="0">选择批次</option>
                            <?php if(is_array($batch)): $i = 0; $__LIST__ = $batch;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>" <?php echo ($detail['fid'] == $key?'selected':'');?>><?php echo ($vo); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 姓名</label>
                    <div class="layui-input-block">
                        <input type="text" name="userName" required value="<?php echo (isset($detail['userName'])?$detail['userName']:'');?>" lay-verify="required" placeholder="请输入客户姓名" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 手机号</label>
                    <div class="layui-input-block">
                        <input type="text" name="userPhone" required value="<?php echo (isset($detail['userPhone'])?$detail['userPhone']:'');?>" lay-verify="required" placeholder="请输入客户手机号" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 代理</label>
                    <div class="layui-input-block">
                        <select name="agent" lay-verify="required">
                            <option value="0">选择代理</option>
                            <?php if(is_array($agent)): $i = 0; $__LIST__ = $agent;if( count($__LIST__)==0 ) : echo "" ;else: foreach($__LIST__ as $key=>$vo): $mod = ($i % 2 );++$i;?><option value="<?php echo ($key); ?>" <?php echo ($detail['fid'] == $key?'selected':'');?>><?php echo ($vo); ?></option><?php endforeach; endif; else: echo "" ;endif; ?>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 地区</label>
                    <div class="layui-input-inline">
                        <select name="province" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="city" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                    <div class="layui-input-inline">
                        <select name="district" class="state" lay-filter="state" lay-verify="required">
                            <option value="0">请选择</option>
                        </select>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 详细地址</label>
                    <div class="layui-input-block">
                        <input type="text" name="userAddress" required value="<?php echo (isset($detail['userAddress'])?$detail['userAddress']:'');?>" lay-verify="required" placeholder="请输入客户地址" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 购买类型</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="buyType" lay-skin="switch" lay-text="精品|普通" <?php echo ((isset($detail['hide']) && $detail['hide']==1)?'checked':'');?>>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 购买数量</label>
                    <div class="layui-input-block">
                        <input type="text" name="buyNumber" required value="<?php echo (isset($detail['buyNumber'])?$detail['buyNumber']:'');?>" lay-verify="required" placeholder="请输入购买数量" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"><span style="color:red">*</span> 付款单价</label>
                    <div class="layui-input-block">
                        <input type="text" name="buyPrice" required value="<?php echo (isset($detail['buyPrice'])?$detail['buyPrice']:'');?>" lay-verify="required" placeholder="请输入购买单价" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 破损重发</label>
                    <div class="layui-input-block">
                        <input type="checkbox" name="isRewire" lay-skin="switch" lay-text="破损|不是" <?php echo ((isset($detail['hide']) && $detail['hide']==1)?'checked':'');?>>
                    </div>
                </div>
                <div class="layui-form-item">
                    <label class="layui-form-label"> 备注</label>
                    <div class="layui-input-block">
                        <input type="text" name="remarks" required value="<?php echo (isset($detail['remarks'])?$detail['remarks']:'');?>"  placeholder="请输入备注信息" class="layui-input">
                    </div>
                </div>
                <div class="layui-form-item">
                    <div class="layui-input-block">
                        <button class="layui-btn" lay-submit lay-filter="admin-form">立即提交</button>
                        <button type="reset" class="layui-btn layui-btn-primary">重置</button>
                    </div>
                </div>
            </form>
        </div>
    </fieldset>

</div>

    <?php if(isset($detail['id'])): ?><script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    $.ajax({
                        type: "POST",
                        url: '<?php echo U("edit");?>',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });

            });
        </script>
        <?php else: ?>
        <script>
            layui.use('form', function(){
                var form = layui.form();
                form.on('submit(admin-form)', function(data){
                    //console.log(data.field);
                    $.ajax({
                        type: "POST",
                        url: '<?php echo U("add");?>',
                        data: data.field,
                        success: function(msg){
                            if( msg.code == 1 ){
                                parent.location.reload();
                            }else{
                                parent.layer.msg(msg.msg, {
                                    icon: 5,
                                    shade: [0.6, '#393D49'],
                                    time:1500
                                });
                            }
                        }
                    });
                    return false;
                });
            });

            layui.use('form', function(){
                //如果有需要到镇的改改就可以实现
                var form = layui.form(),
                        layer = layui.layer,
                        $ = layui.jquery;
                var url =  '<?php echo U("getArea");?>'; //数据请求地址
                var province = "广东省"; //编辑需要的省
                var city = "广州市"; //编辑需要的市
                var district = "天河区"; //编辑需要的县/区
                getJSON(url,$("select[name='province']").closest("div"));
                form.on('select(state)', function(data){
                    $that = $(data.elem);
                    urls = url+"&id="+data.value;
                    getJSON(urls,$that.closest("div").next());
                });
                function getJSON(urls,even){
                    $.getJSON(urls, function(json){
                        var pid = 0;
                        var name = even.find("select").attr("name");
                        var select = "<select name=\"" + name + "\" lay-filter=\"state\">";
                        select += "<option value=\"0\">请选择 </option>";
                        $(json).each(function(){
                            select += "<option value=\"" + this.id + "\"";
                            if(province == this.value || city == this.value || district == this.value){
                                select += " selected=\"selected\" ";
                                pid = this.id;
                            }
                            select += ">" + this.value + "</option>";
                        });
                        select += "</select>";
                        even.html(select);
                        var nextName = even.next().find("select").attr("name");
                        even.next().html("<select name=\"" + nextName + "\" lay-filter=\"state\"><option value=\"0\">请选择 </option></select>");
                        form.render('select');
                        if(pid != 0){
                            getJSON(url+"?id="+pid,even.next());
                        }
                    });
                }
            });


        </script><?php endif; ?>

</body>
</html>